<template>
  <div class="lend-record">
    <div class="title-box">该员工仍有未处理的借支记录，请优先处理</div>

    <div class="lend-con">
      <div class="content-box1">
        <img :src="userUrl" class="pic1" v-if="userUrl" onclick="return false"/>
        <div class="pic2" v-else></div>
        <div class="user-box">
          <span class="name">{{name}}</span>
          <span class="number">{{number}}</span>
        </div>
        <div class="money">借支金额：{{money}}元</div>
      </div>

      <div class="content-box2">
        <span class="day">借支日期：{{time}}</span>
        <div class="btn-box">
          <button type="button" class="refuse" @click="refuse">拒绝</button>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  import {baseUrl} from "../../../config/env"

  export default {
    data() {
      return {
        money: "",
        name: "",
        time: "",
        number: "",
        userUrl: "",
        userSign: "",
        id: "",
        userId: ""
      }
    },
    mounted() {
      this.money = this.$route.query.money;
      this.name = this.$route.query.name;
      this.time = this.$route.query.time;
      this.number = this.$route.query.number;
      this.userUrl = this.$route.query.userUrl;
      this.userId = this.$route.query.userId;
      this.id = this.$route.query.id;
      let base64 = require('js-base64').Base64;
      this.userSign = base64.decode(sessionStorage.getItem("success"));
    },
    methods: {
      refuse() {
        this.$vux.loading.show({
          text: '加载中',
        });
        let time = (new Date()).getTime();
        let url = baseUrl + "/resident/update_lend_money_status?timestamp=" + time;
        let param = {"sgin": this.userSign, "timestamp": time};
        let signature = this.$signature(url, param);

        this.axios.get(baseUrl + "/resident/update_lend_money_status?sgin=" + this.userSign + "&status=2" + "&id=" + this.id + "&type=1" + "&auth=" + signature + "&timestamp=" + time).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0) {
            if (resultObj.data == 0) {
              this.$vux.toast.text("审核失败，请重试", "middle");
            } else {
              this.$router.push({path: "/leavebill", query: {"userId": this.userId}});
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch(() => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      }
    }
  }
</script>

<style lang="stylus" scoped>
  @import "../../../assets/stylus/mixin.styl"

  .lend-record
    wh(100%, 100%)
    background: rgba(242, 242, 242, 1)
    overflow: hidden
    .title-box
      fj(center, center)
      wh(100%, 0.8rem)
      size-color(0.373rem, rgba(255, 255, 255, 1))
      background: rgba(255, 172, 83, 1)
    .lend-con
      display: flex
      flex-direction: column
      wh(100%, 2.827rem)
      background: rgba(255, 255, 255, 1)
      border-bottom: 0.027rem solid rgba(242, 242, 242, 1)
      &:last-child
        border-bottom: none
      .content-box1
        display: flex
        wh(auto, 1.387rem)
        margin-top: 0.373rem
        margin-left: 0.32rem
        margin-right: 0.32rem
        margin-bottom: 0.213rem
        .pic1
          wh(1.387rem, 1.387rem)
          border-radius(50%)
        .pic2
          wh(1.387rem, 1.387rem)
          border-radius(50%)
          background: rgba(242, 242, 242, 1)
        .user-box
          display: flex
          justify-content: center
          flex-direction: column
          margin-left: 0.267rem
          .name
            padding-bottom: 0.113rem
            size-color(0.453rem, rgba(51, 51, 51, 1))
          .number
            padding-top: 0.113rem
            size-color(0.373rem, rgba(102, 102, 102, 1))
        .money
          margin-left: auto
          margin-top: 0.227rem
          size-color(0.4rem, rgba(60, 175, 255, 1))
          font-weight: bold
      .content-box2
        fj(space-between, center)
        wh(100%, 0.64rem)
        .day
          margin-left: 0.32rem
          size-color(0.347rem, rgba(204, 204, 204, 1))
        .btn-box
          margin-right: 0.32rem
          wh(auto, 0.64rem)
          .refuse
            wh(1.92rem, 0.64rem)
            line-height: 0.64rem
            text-align: center
            border: 0.027rem solid rgba(255, 83, 83, 1)
            border-radius(0.32rem)
            size-color(0.347rem, rgba(255, 83, 83, 1))
            background: #FFF
        .title
          margin-right: 0.32rem
          size-color(0.373rem, rgba(153, 153, 153, 1))
        .active
          color: rgba(255, 83, 83, 1)
</style>
